// pages/my/refund/refund.ts
// @ts-ignore
import Toast from 'tdesign-miniprogram/toast/index'

import { cancelAnOrder, cancelAnReOrder } from '../../../http/api/orderService'

Page({
    /**
     * 页面的初始数据
     */
    data: {
        info: {},
        refundStr: ''
    } as any,
    handlerChange(e: any) {
        this.setData({
            refundStr: e.detail.value
        })
    },
    async cancelOrder() {
        console.log(this.data.refundStr, this.data.info)
        if (this.data.refundStr == '') {
            Toast({
                context: this,
                selector: '#t-toast',
                message: this.data.info.type == -1 ? '请输入取消原因' : '请输入退款原因！',
                theme: 'warning',
                direction: 'column'
            })
            return
        }
        if (this.data.info.type == 0 || this.data.info.type == -1) {
            await cancelAnOrder(this.data.info.id)
            wx.navigateBack()
        } else if (this.data.info.type == 1) {
            await cancelAnReOrder(this.data.info.id, this.data.info.money)
            wx.navigateBack()
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options: any) {
        console.log(options)
        this.setData({
            info: {
                id: options.orderId,
                money: options.money,
                type: options.type
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {}
})
